
XCP_DRIVER_VERSION =0x10 # version 1.0 */

XCP_SEG_INITIAL_DATA_PAGE_IDX =0x00

XCP_TRANSPORT_LAYER_CAN     =1
XCP_TRANSPORT_LAYER_TCPIP   =2
XCP_TRANSPORT_LAYER_INVALID =3

XCP_CON_STATE_RESUME       =2
XCP_CON_STATE_DISCONNECTED =0
XCP_CON_STATE_CONNECTED    =1

#ifdef XCP_DBG_OVER_XCP
# Use for xcp dynamic debug itself */
XCP_DEBUG_DISABLE_ALL =0x00
XCP_DEBUG_ENABLE_ALL  =0xFFFFFFFF
#endif

# XCP Command IDs */
# Used to check if a command is valid.
# Valid XCP commands are between 0xC0 and 0xFF.
XCP_MIN_VALID_CMD =0xC0


# Standard commands=0xF1-=0xFF,=0xC0,=0x00
XCP_CMD_CONNECT            =0xFF
XCP_CMD_DISCONNECT         =0xFE
XCP_CMD_GET_STATUS         =0xFD
XCP_CMD_GET_COMM_MODE_INFO =0xFB
XCP_CMD_SYNCH              =0xFC
XCP_CMD_SET_REQUEST        =0xF9
XCP_CMD_SET_MTA            =0xF6
XCP_CMD_UPLOAD             =0xF5
XCP_CMD_SHORT_UPLOAD       =0xF4
XCP_CMD_BUILD_CHECKSUM     =0xF3
XCP_CMD_TRANSPORT_LAYER    =0xF2
# Transport Layer Sbcommands on CAN and ETH=0xFF
XCP_SUB_CMD_GET_SLAVE_ID =0xFF
# Transport Layer Sbcommands on CAN=0xFE, =0xFD
XCP_SUB_CMD_GET_DAQ_ID =0xFE
XCP_SUB_CMD_SET_DAQ_ID =0xFD
# Calibration commands=0xEC-=0xF0
XCP_CMD_DOWNLOAD =0xF0
# Page switching commands=0xE4-=0xEB
XCP_CMD_SET_CAL_PAGE     =0xEB
XCP_CMD_GET_CAL_PAGE     =0xEA
GET_PAG_PROCESSOR_INFO   =0xE9
XCP_CMD_GET_SEGMENT_INFO =0xE8
XCP_CMD_GET_PAGE_INFO    =0xE7
XCP_CMD_SET_SEGMENT_MODE =0xE6
XCP_CMD_GET_SEGMENT_MODE =0xE5
XCP_CMD_COPY_CAL_PAGE    =0xE4
# Basic data acqisition and stimlation commands=0xC5-=0xE2,=0xC0,=0x01,=0x02
# Static data acqisition and stimlation commands=0xD8,=0xE3
XCP_CMD_CLEAR_DAQ_LIST          =0xE3
XCP_CMD_SET_DAQ_PTR             =0xE2
XCP_CMD_WRITE_DAQ               =0xE1
XCP_CMD_SET_DAQ_LIST_MODE       =0xE0
XCP_CMD_GET_DAQ_LIST_MODE       =0xDF
XCP_CMD_START_STOP_DAQ_LIST     =0xDE
XCP_CMD_START_STOP_SYNCH        =0xDD
XCP_CMD_GET_DAQ_CLOCK           =0xDC
XCP_CMD_GET_DAQ_PROCESSOR_INFO  =0xDA
XCP_CMD_GET_DAQ_RESOLUTION_INFO =0xD9
XCP_CMD_GET_DAQ_EVENT_INFO      =0xD7
# Dynamic data acqisition and stimlation commands=0xD3-=0xD6
XCP_CMD_FREE_DAQ        =0xD6
XCP_CMD_ALLOC_DAQ       =0xD5
XCP_CMD_ALLOC_ODT       =0xD4
XCP_CMD_ALLOC_ODT_ENTRY =0xD3
# Non-volatile memory programming commands=0xC8-=0xD2
# Time synchronization commands=0xC6
# Command spaces for related ASAM standards=0xC0,=0xFC,=0xFD

# Message length inclding ID for varios messages that have a payload.
XCP_CMD_CONNECT_LEN            =2
XCP_CMD_SET_REQUEST_LEN        =4
XCP_CMD_SET_MTA_LEN            =8
XCP_CMD_UPLOAD_LEN             =2
XCP_CMD_SHORT_UPLOAD_LEN       =8
XCP_CMD_BUILD_CHECKSUM_LEN     =8
XCP_CMD_TRANSPORT_LAYER_LEN    =8
XCP_CMD_SET_CAL_PAGE_LEN       =4
XCP_CMD_GET_CAL_PAGE_LEN       =3
XCP_CMD_GET_SEGMENT_INFO_LEN   =5
XCP_CMD_GET_PAGE_INFO_LEN      =4
XCP_CMD_SET_SEGMENT_MODE_LEN   =3
XCP_CMD_GET_SEGMENT_MODE_LEN   =3
XCP_CMD_COPY_CAL_PAGE_LEN      =5
XCP_CMD_CLEAR_DAQ_LIST_LEN     =4
XCP_CMD_SET_DAQ_PTR_LEN        =6
XCP_CMD_WRITE_DAQ_LEN          =8
XCP_CMD_SET_DAQ_LIST_MODE_LEN  =8
XCP_CMD_GET_DAQ_LIST_MODE_LEN  =4
XCP_CMD_START_STOP_DAQ_LEN     =4
XCP_CMD_START_STOP_SYNCH_LEN   =2
XCP_CMD_DOWNLOAD_LEN           =3
XCP_CMD_ALLOC_DAQ_LEN          =4
XCP_CMD_ALLOC_ODT_LEN          =5
XCP_CMD_ALLOC_ODT_ENTRY_LEN    =6
XCP_CMD_GET_DAQ_EVENT_INFO_LEN =4

# Response IDs to Master
XCP_CMD_RES =0xFF
XCP_CMD_ERR =0xFE
XCP_CMD_EV  =0xFD
# End XCP Command IDs */

# XCP Event Codes */
XCP_EVENT_CODE_EV_DAQ_OVERLOAD =0x06
# End XCP Event Codes */

# XCP Error Codes */
XCP_ERR_CODE_CMD_SYNCH             =0x00
XCP_ERR_CODE_BUSY                  =0x10
XCP_ERR_CODE_ERR_CMD_UNKNOWN       =0x20
XCP_ERR_CODE_CMD_SYNTAX            =0x21
XCP_ERR_CODE_ERR_OUT_OF_RANGE      =0x22
XCP_ERR_CODE_ERR_WRITE_PROTECTED   =0x23
XCP_ERR_CODE_ERR_PAGE_NOT_VALID    =0x26
XCP_ERR_CODE_ERR_MODE_NOT_VALID    =0x27
XCP_ERR_CODE_ERR_SEGMENT_NOT_VALID =0x28
XCP_ERR_CODE_ERR_SEQUENCE          =0x29
XCP_ERR_CODE_ERR_MEMORY_OVERFLOW   =0x30
XCP_ERR_CODE_GENERIC               =0x31
# End XCP Error Codes */

XCP_PROTOCOL_LAYER_VERSION  =0x01
XCP_TRANSPORT_LAYER_VERSION =0x01

# Attribtes of the CONNECT reqest
XCP_CONNECT_MODE_NORMAL =0
# Other CONNECT modes can be defined here or in ftre, may be generated.

# Attribtes of Resorce mask, sed by CONNECT
XCP_RESOURCE_MASK_CAL_PAGE =0x01 << 0 # Calibration paging
XCP_RESOURCE_MASK_DAQ      =0x01 << 2 # DAQ
XCP_RESOURCE_MASK_STIM     =0x01 << 3 # STIM
XCP_RESOURCE_MASK_PGM      =0x01 << 4 # Programming
XCP_RESOURCE_MASK_DBG      =0x01 << 5 # Software Debgging
# STIM and Programming are not spported in NVOS.

# BYTE_ORDER for COMM_MODE_BASIC mask
BASIC_BYTE_ORDER_INTEL    =0
BASIC_BYTE_ORDER_MOTOROLA =1
# ADDR_GRANULARITY for COMM_MODE_BASIC mask
ADDR_GRANULARITY_BYTE  =0 # Address granlarity of 1 byte
ADDR_GRANULARITY_WORD  =1 # Address granlarity of 2 bytes
ADDR_GRANULARITY_DWORD =2 # Address granlarity of 4 bytes
# Attribtes of COMM_MODE_BASIC mask, sed by CONNECT
XCP_COMM_MODE_BASIC_BYTE_ORDER       =BASIC_BYTE_ORDER_INTEL << 0
XCP_COMM_MODE_BASIC_ADDR_GRANULARITY =ADDR_GRANULARITY_BYTE << 1
XCP_COMM_MODE_BASIC_SLAVE_BLOCK_MODE =0x00 << 6 # Slave block mode disabled.
XCP_COMM_MODE_BASIC_OPTIONAL         =0x00 << 7 # Disable gathering of additional info via GET_COMM_MODE_INFO.

# Attribtes of SET_REQUEST mode bitmask
XCP_SET_REQUEST_STORE_CAL_REQ_OFFSET           =0
XCP_SET_REQUEST_STORE_CAL_REQ_MASK             =0x01 << XCP_SET_REQUEST_STORE_CAL_REQ_OFFSET
XCP_SET_REQUEST_STORE_DAQ_REQ_NO_RESUME_OFFSET =1
XCP_SET_REQUESTSTORE_DAQ_REQ_NO_RESUME_MASK    =0x01 << XCP_SET_REQUEST_STORE_DAQ_REQ_NO_RESUME_OFFSET
XCP_SET_REQUEST_STORE_DAQ_REQ_RESUME           =2
XCP_SET_REQUEST_STORE_DAQ_REQ_RESUME_MASK      =0x01 << XCP_SET_REQUEST_STORE_DAQ_REQ_RESUME
XCP_SET_REQUEST_CLEAR_DAQ_REQ                  =3
XCP_SET_REQUEST_CLEAR_DAQ_REQ_MASK             =0x01 << XCP_SET_REQUEST_CLEAR_DAQ_REQ

# Attribtes of SET_SEGMENT_MODE mode bitmask
XCP_SET_SEGMENT_MODE_FREEZE_OFFSET =0
XCP_SET_SEGMENT_MODE_FREEZE_MASK   =0x01 << XCP_SET_SEGMENT_MODE_FREEZE_OFFSET

# Vales sed in GET_SEGMENT_INFO
XCP_GET_SEGMENT_INFO_BASIC_ADDR_INFO =0
XCP_GET_SEGMENT_INFO_STD_ADDR_INFO   =1
XCP_GET_SEGMENT_INFO_ADDR_MAP_INFO   =2

GET_SEGMENT_INFO_BASIC_INFO_ADDR =0
GET_SEGMENT_INFO_BASIC_INFO_LEN  =1

GET_SEGMENT_INFO_MAP_IDX_SRC_ADDR  =0
GET_SEGMENT_INFO_MAP_IDX_DEST_ADDR =1
GET_SEGMENT_INFO_MAP_IDX_LEN       =2

# Attribtes of GET_PAGE_INFO PAGE_PROPERTIES bitmask
# Bits 0 and 1 describe the 'ECU_ACCESS_TYPE coding' for a given page.
# with the following possible vales:
# =0x00: ECU access not allowed.
# =0x01: withot XCP only.
# =0x02: with XCP only.
# =0x03: do not care.
PAGE_PROPERTIES_ECU_ACCESS_MASK        =3 << 0
PAGE_PROPERTIES_ECU_ACCESS_NOT_ALLOWED =0 << 0
PAGE_PROPERTIES_ECU_ACCESS_WITHOUT_XCP =1 << 0
PAGE_PROPERTIES_ECU_ACCESS_WITH_XCP    =2 << 0
PAGE_PROPERTIES_ECU_ACCESS_DONT_CARE   =3 << 0
# Bits 2 and 3 describe the 'XCP_READ_ACCESS_TYPE coding' for a given page.
# =0x00: XCP read access not allowed.
# =0x01: withot ECU only.
# =0x02: with ECU only.
# =0x03: do not care.
PAGE_PROPERTIES_XCP_READ_ACCESS_MASK        =3 << 2
PAGE_PROPERTIES_XCP_READ_ACCESS_NOT_ALLOWED =0 << 2
PAGE_PROPERTIES_XCP_READ_ACCESS_WITHOUT_ECU =1 << 2
PAGE_PROPERTIES_XCP_READ_ACCESS_WITH_ECU    =2 << 2
PAGE_PROPERTIES_XCP_READ_ACCESS_DONT_CARE   =3 << 2
# Bits 4 and 5 describe the 'XCP_WRITE_ACCESS_TYPE coding' for a given page.
# =0x00: XCP write access not allowed.
# =0x01: withot ECU only.
# =0x02: with ECU only.
# =0x03: do not care.
PAGE_PROPERTIES_XCP_WRITE_ACCESS_MASK        =3 << 4
PAGE_PROPERTIES_XCP_WRITE_ACCESS_NOT_ALLOWED =0 << 4
PAGE_PROPERTIES_XCP_WRITE_ACCESS_WITHOUT_ECU =1 << 4
PAGE_PROPERTIES_XCP_WRITE_ACCESS_WITH_ECU    =2 << 4
PAGE_PROPERTIES_XCP_WRITE_ACCESS_DONT_CARE   =3 << 4

XCP_COMPRESSION_METHOD_NOT_SUPPORTED          =0x00
XCP_COMPRESSION_METHOD_SUPPORTED              =0x01
XCP_COMPRESSION_METHOD_RESERVED               =0x02
XCP_COMPRESSION_METHOD_SUPPORTED_AND_REQUIRED =0x03

XCP_ENCRYPTION_METHOD_NOT_SUPPORTED          =0x00
XCP_ENCRYPTION_METHOD_SUPPORTED              =0x01
XCP_ENCRYPTION_METHOD_RESERVED               =0x02
XCP_ENCRYPTION_METHOD_SUPPORTED_AND_REQUIRED =0x03

# Attribtes of GET/SET_CAL_PAGE mode mask
XCP_SET_CAL_PAGE_MODE_ALL_SEGMENT_OFFSET =7
SET_CAL_PAGE_MODE_ECU_ACCESS_OFFSET      =0
SET_CAL_PAGE_MODE_XCP_ACCESS_OFFSET      =1

# Attribtes of GET/SET_DAQ_LIST_MODE 'mode' mask.
XCP_DAQ_LIST_MODE_SELECTED_OFFSET    =0
XCP_DAQ_LIST_MODE_DIRECTION_OFFSET   =1
XCP_DAQ_LIST_MODE_TIMESTAMP_OFFSET   =4
XCP_DAQ_LIST_MODE_SET_PID_OFF_OFFSET =5
XCP_DAQ_LIST_MODE_RUNNING_OFFSET     =6
XCP_DAQ_LIST_MODE_RESUME_OFFSET      =7

# Masks for GET/SET_DAQ_LIST_MODE 'mode' mask.
XCP_DAQ_LIST_MODE_SELECTED_MASK    =0x01 << XCP_DAQ_LIST_MODE_SELECTED_OFFSET
XCP_DAQ_LIST_MODE_DIRECTION_MASK   =0x01 << XCP_DAQ_LIST_MODE_DIRECTION_OFFSET
XCP_DAQ_LIST_MODE_TIMESTAMP_MASK   =0x01 << XCP_DAQ_LIST_MODE_TIMESTAMP_OFFSET
XCP_DAQ_LIST_MODE_SET_PID_OFF_MASK =0x01 << XCP_DAQ_LIST_MODE_SET_PID_OFF_OFFSET
XCP_DAQ_LIST_MODE_RUNNING_MASK     =0x01 << XCP_DAQ_LIST_MODE_RUNNING_OFFSET
XCP_DAQ_LIST_MODE_RESUME_MASK      =0x01 << XCP_DAQ_LIST_MODE_RESUME_OFFSET

# START_STOP_DAQ_LIST
XCP_DAQ_LIST_MODE_STOP   =0
XCP_DAQ_LIST_MODE_START  =1
XCP_DAQ_LIST_MODE_SELECT =2

XCP_START_STOP_SYNCH_MODE_STOP_ALL       =0
XCP_START_STOP_SYNCH_MODE_START_SELECTED =1
XCP_START_STOP_SYNCH_MODE_STOP_SELECTED  =2

# GET_DAQ_PROCESSOR_INFO
XCP_DAQ_CONFIG_TYPE_BIT_NUM     =0
XCP_PRESCALER_SUPPORTED_BIT_NUM =1
XCP_RESUME_SUPPORTED_BIT_NUM    =2
XCP_BIT_STIM_SUPPORTED_BIT_NUM  =3
XCP_TIMESTAMP_SUPPORTED_BIT_NUM =4
XCP_PID_OFF_SUPPORTED_BIT_NUM   =5
XCP_OVERLOAD_MSB_BIT_NUM        =6
XCP_OVERLOAD_EVENT_BIT_NUM      =7

XCP_DAQ_CONFIG_TYPE_STATIC  =0
XCP_DAQ_CONFIG_TYPE_DYNAMIC =1

# GET_DAQ_RESOLUTION_INFO
XCP_DAQ_TS_SIZE_OFFSET       =0
XCP_DAQ_TS_FIXED_FLAG_OFFSET =3
XCP_DAQ_TS_UINT_OFFSET       =4

# GET_DAQ_CLOCK
XCP_DAQ_NO_TIME_STAMP =0
XCP_DAQ_SIZE_BYTE     =1
XCP_DAQ_SIZE_WORD     =2
XCP_DAQ_SIZE_DWORD    =4

# XCP TRAP PREVENT
# XCP_PREVENT_SRC_READ_TRAP  =STD_ON
# XCP_PREVENT_DST_WRITE_TRAP =STD_ON

# GET_STATUS response
XCP_GET_STATUS_RESP_CUR_SESSION_STATUS_DAQ_RUNNING_MASK =1 << 6
XCP_GET_STATUS_RESP_CUR_SESSION_STATUS_RESUME_MASK      =1 << 7

#endif # XCP_DEFINITIONS_H */


# 其他常量
XCP_POSITIVE_RESP_LEN  =1
XCP_ERROR_RESP_LEN     =2
ETHXCP_HEADER_SIZE_BYTES =4

# 长度常量
XCP_MAX_CTO_LEN = 64
XCP_MAX_CTO_LEN = 64

XCP_CMD_CONNECT_RESP_LEN                   =8
XCP_CMD_GET_STATUS_RESP_LEN                =6
XCP_CMD_UPLOAD_RESP_LEN                    =XCP_MAX_CTO_LEN
XCP_CMD_SHORT_UPLOAD_RESP_LEN              =XCP_MAX_CTO_LEN
XCP_CMD_BUILD_CHECKSUM_RESP_LEN            =8
XCP_CMD_GET_DAQ_ID_RESP_LEN                =8
XCP_CMD_GET_CAL_PAGE_RESP_LEN              =4
XCP_CMD_GET_SEGMENT_INFO_RESP_LEN          =8
XCP_CMD_GET_SEGMENT_STD_ADDR_INFO_RESP_LEN =6
XCP_CMD_GET_PAGE_INFO_RESP_LEN             =3
XCP_CMD_GET_SEGMENT_MODE_RESP_LEN          =3
XCP_CMD_GET_DAQ_LIST_MODE_RESP_LEN         =8
XCP_CMD_START_STOP_DAQ_LIST_RESP_LEN       =2
XCP_CMD_GET_DAQ_PROCESSOR_INFO_RESP_LEN    =8
XCP_CMD_GET_DAQ_RESOLUTION_INFO_RESP_LEN   =8
XCP_CMD_GET_DAQ_CLOCK_RESP_LEN             =8
XCP_CMD_GET_PAG_PROCESSOR_INFO_RESP_LEN    =3
XCP_CMD_GET_DAQ_EVENT_INFO_RESP_LEN        =7